 
/*
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "msAttribute_Child.h"
#include "eigen3/Eigen/src/Core/products/GeneralBlockPanelKernel.h"


/*
std::istream& operator>>( std::istream& in, double& obj){
 
  string str;in >> str;
  obj=atof(str.c_str());
  return in;
  }
std::istream& operator>>( std::istream& in, int& obj){
 
  string str;in >> str;
  obj=atoi(str.c_str());
  return in;
  }
std::istream& operator>>( std::istream& in, bool& obj){
 
  string str;in >> str;
  obj=atoi(str.c_str());
  return in;
  }
std::istream& operator>>( std::istream& in, size_t& obj){
 
  string str;in >> str;
  obj=atoi(str.c_str());
  return in;
  }
std::istream& operator>>( std::istream& in, string& obj){
 
  string str;in >> str;
  obj=str;
  return in;
  }*/
/*
std::istream& operator>>( std::istream& in, std::map<std::string , double >& obj) {

 std::vector< std::string > strs;
 std::string str;
 getline(in,str);
 fillVecFromString( str , strs , " ");
 
 std::vector< std::string >::const_iterator it = strs.begin();
 
 obj.clear();

 for(;it!=strs.end();++it) {

   std::vector< std::string > strs2;
   fillVecFromString( *it , strs2 , ":");
   obj[strs2[0]] =  boost::lexical_cast <double> (strs2[1]);
   }
 return in;
 }
*/

namespace atomism{


void lexical_cast( std::string str, double& obj) { obj=boost::lexical_cast <double> (str);};
void lexical_cast( std::string str, int& obj)    { obj=atoi(str.c_str()); };
void lexical_cast( std::string str, bool& obj)   { obj=atoi(str.c_str()); };
void lexical_cast( std::string str, size_t& obj) { obj=atoi(str.c_str()); };
void lexical_cast( std::string str, string& obj) { obj=str; };


void lexical_cast(  std::string str, std::vector< double >& obj){ fillVecFromString( str , obj , " ");
 								 }

void lexical_cast(  std::string str, std::vector< int >& obj){	fillVecFromString( str , obj , " ");
 							      }
// [1,1,1]:2. [1,2,0]:1.5
void lexical_cast(  std::string str, std::map< vector<int> , double >& obj){
 
 vector<std::string> strs;
 fillVecFromString( str , strs , " ");
 std::vector< std::string >::const_iterator it = strs.begin();
 obj.clear();
 for(;it!=strs.end();++it) { 
    
     std::vector< std::string > strs2;
     fillVecFromString( *it , strs2 , ":");

     if( strs2.size()!=2 ) return; 
     vector<int> indices;
     fillVecFromString<int>(strs2[0].substr(1,strs2[0].length()-2) , indices, ",");
     obj[indices]=atof( strs2[1].c_str() ); 
     }
 }


void lexical_cast(  std::string str, std::map<std::string , double >& obj){
 
 vector<std::string> strs;
 fillVecFromString( str , strs , " ");
 
 std::vector< std::string >::const_iterator it = strs.begin();
 
 obj.clear();

 for(;it!=strs.end();++it) { 
    
     std::vector< std::string > strs2;
     fillVecFromString( *it , strs2 , ":");

     if( strs2.size()!=2 ) return; 
   
     obj[strs2[0]]=atof( strs2[1].c_str() ); 
     }
 }

 // [1,1,1.5] [1,2.3,0,5.5]
void lexical_cast(  std::string str, std::vector< std::vector<double> >& obj){
  
 vector<std::string> strs;
 fillVecFromString( str , strs , " ");
 std::vector< std::string >::const_iterator it = strs.begin();
 obj.clear();
 for(;it!=strs.end();++it) { 
    
     vector<double> indices;
     fillVecFromString<double>( (*it).substr(1,(*it).length()-2) , indices, ",");
     obj.push_back(indices);
     }
  
 }


std::ostream& operator<<( std::ostream& out , const msAttributeBase& obj) { return out<<obj.get();
 									    }

/*
std::ostream& operator<<( std::ostream& out , const std::map<std::string , double >& obj) {

 typedef typename std::map<std::string , double >::const_iterator iterator;
 iterator it = obj.begin();
 for(;it!=obj.end();++it) out<<(*it).first<<":"<<(*it).second<<" ";
 return out;
 }*/


}
